﻿// -----------------------------------------------------------------------
// <copyright company="Christoph van der Fecht - VDsoft">
// This code can be used in commercial, free and open source projects.
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VDsoft.SeriesNewsReader.ViewModel
{
	/// <summary>
	/// Locator that stores all view models.
	/// </summary>
	public class ViewModelLocator
	{
		/// <summary>
		/// Current instance of the <see cref="MainViewModel"/> class.
		/// </summary>
		private static MainViewModel MainViewInstance = null;

		/// <summary>
		/// Current instance of the <see cref="OptionsViewModel"/> class.
		/// </summary>
		private static OptionsViewModel OptionsViewInstance = null;

		/// <summary>
		/// Initializes a new instance of the <see cref="ViewModelLocator"/> class.
		/// </summary>
		public ViewModelLocator()
		{

		}

		#region Tokens

		/// <summary>
		/// Token for all messages that contain series information.
		/// </summary>
		public static object SeriesToken = new object();

		/// <summary>
		/// Token for all messages that contain tv movie information.
		/// </summary>
		public static object TvMovieToken = new object();

		/// <summary>
		/// Token for a series filter result.
		/// </summary>
		public static object SeriesFilterResult = new object();

		/// <summary>
		/// Token for a tv movie filter result.
		/// </summary>
		public static object TvMoveFilterResult = new object();

		/// <summary>
		/// Token for all messages that contains language informaiton.
		/// </summary>
		public static object LanguageToken = new object();

		#endregion

		/// <summary>
		/// Gets the current instance of the main view.
		/// </summary>
		public static MainViewModel MainView
		{
			get
			{
				if (MainViewInstance == null)
				{
					MainViewInstance = new MainViewModel();
				}

				return MainViewInstance;
			}
		}

		/// <summary>
		/// Gets the current instance of the <see cref="OptionsViewModel"/> class.
		/// </summary>
		public static OptionsViewModel OptionsView
		{
			get
			{
				if (OptionsViewInstance == null)
				{
					OptionsViewInstance = new OptionsViewModel();
				}

				return OptionsViewInstance;
			}
		}

		/// <summary>
		/// Cleans up all view model instance.
		/// </summary>
		public static void Cleanup()
		{
			CleanupMainView();
			CleanupOptionsView();
		}

		/// <summary>
		/// Cleans up the <see cref="MainViewModel"/> instance.
		/// </summary>
		private static void CleanupMainView()
		{
			if (MainViewInstance != null)
			{
				MainViewInstance.Cleanup();
				MainViewInstance = null;
			}
		}

		/// <summary>
		/// Cleans the current instance of the <see cref="OptionsViewModel"/> class.
		/// </summary>
		private static void CleanupOptionsView()
		{
			if (OptionsViewInstance != null)
			{
				OptionsViewInstance.Cleanup();
				OptionsViewInstance = null;
			}
		}
	}
}
